from langgraph.graph import StateGraph,START,END
from langgraph.graph.message import MessagesState

'''
MessageState实现消息追加
1.创建保存图的状态的字典 继承MessageState
2.创建智能体   添加 messages字段的value
3.创建带状态的图
4.创建节点 节点和智能体绑定
5.编译图
6.使用：通过图执行智能体和管理  invoke 测试messages字段的value， 如 {"messages":"hello", "foo":10}
'''

class State(MessagesState):
    foo:int

def agent_01(state):
    return {"messages":"world","foo":[state["foo"] + 1]}

builder = StateGraph(State)
builder.add_node("node_01",agent_01)
builder.add_edge(START,"node_01")
builder.add_edge("node_01",END)
graph = builder.compile()

r = graph.invoke({"messages":"hello","foo":10})
print(r)